<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Class 与 Style 绑定</title>
</head>
<style>
    .static {
        width: 300px;
    }
    
    .active {
        height: 20px;
        background-color: aquamarine;
    }
    
    .error {
        background-color: rgb(250, 169, 169);
        margin: auto;
    }
</style>

<body>
    <div id="app">
        <!-- v-bind的基本用法 -->
        <a v-bind:href="url">百度一下</a>
        <br>
        <br>
        <!-- v-bind对象语法 -->
        <div :class="{'active':isActive}">v-bind对象语法 切换属性</div>
        <br>
        <div class="static" :class="{'active':isActive,'error':isError}">
            <p> v-bind对象语法传入多个属性</p>
        </div>
        <br>
        <div :class='classes'>v-bind对象语法绑定一计算属性</div>
        <br>
        <!-- v-bind数组语法 -->
        <div :class="[activeCls,errorCls]">v-bind数组语法</div>
        <br>
        <div :class="[isActive?activeCls:'',errorCls]">使用三元表达式根据条件切换class</div>
        <br>
        <button :class="butClass">点击</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                url: 'https://www.baidu.com',
                isActive: true,
                isError: false,
                error: null,
                activeCls: 'active',
                errorCls: 'error',
                size: 'large',
                disabled: true,
            },
            computed: {
                classes: function() {
                    return {
                        active: this.isActive && !this.error,
                        'text-fail': this.error && this.error.type === 'fail'
                    }
                },
                butClass: function() {
                    return [
                        'btn', {
                            ['btn-' + this.size]: this.size !== '',
                            ['btn-disabled']: this.disabled
                        }
                    ]
                }

            }
        })
    </script>

</body>

</html>